// 该文件是专门用于创建整个应用的路由器

// 第一步引入插件(本质是一个构造函数)
// import VueRouter from 'vue-router'
import {createRouter, createWebHistory} from "vue-router";
// 引入一下用到的组件
import ProcessManager from '../views/process/ProcessManager.vue'
import SquareLakeFlow from '../views/process/SquareLakeFlow.vue'
import ProcessCompManager from '../views/comp/ProcessCompManager.vue'
import ProcessThreadConfigManager from "@/views/thread/ProcessThreadConfigManager.vue";
import ProcessDataSourceConfigManager from "@/views/datasource/ProcessDataSourceConfigManager.vue";
import SqlRunner from "@/views/datasource/SqlRunner.vue";

import ApiConfig from "@/views/restapi/RestApiConfig.vue";
import JobManager from "@/views/job/JobManager.vue";
import Login from "@/views/login/SqLogin.vue";
import {useStore} from "vuex";
import ProcessRunnerInfo from "@/views/process/ProcessRunnerInfo.vue";

// 第二步创建router实例对象并暴露
const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            // path是路径
            path: "/",
            name: "home",
            //跳转的组件
            component: ProcessManager
        },
        {
            // path是路径
            path: "/flow",
            name: "flow",
            props: true,
            //跳转的组件
            component: SquareLakeFlow
        },
        {
            // path是路径
            path: "/comp",
            name: "comp",
            props: true,
            //跳转的组件
            component: ProcessCompManager
        },
        {
            // path是路径
            path: "/thread",
            name: "thread",
            props: true,
            //跳转的组件
            component: ProcessThreadConfigManager
        },
        {
            // path是路径
            path: "/datasource",
            name: "datasource",
            props: true,
            //跳转的组件
            component: ProcessDataSourceConfigManager
        },
        {
            // path是路径
            path: "/datasource/sqlRunner",
            name: "sqlRunner",
            props: true,
            //跳转的组件
            component: SqlRunner
        },
        {
            // path是路径
            path: "/job",
            name: "job",
            props: true,
            //跳转的组件
            component: JobManager
        },
        {
            // path是路径
            path: "/restApi",
            name: "restApi",
            props: true,
            //跳转的组件
            component: ApiConfig
        },
        {
            // path是路径
        path: "/process/runner",
        name: "processRunnerInfo",
        props: true,
        //跳转的组件
      component: ProcessRunnerInfo
    },



        {
            // path是路径
            path: "/login",
            name: "login",
            props: true,
            //跳转的组件
            component: Login
        },
    ],

})


router.beforeEach((to, from, next) => {
    // 登录和注册界面进行选择
    if (to.path === "/login") {
        next()
    } else {
        const store = useStore();
        const dd = store.state.userInfo.isLogin;
        console.log(dd)
        if (!dd) {
            next({
                path: "/login"
            })
        } else {
            // 不写代表直接可以过去
            next()
        }
    }
});
export default router;